'''
@Author: your name
@Date: 2019-06-24 11:32:40
LastEditTime: 2021-03-04 21:47:18
LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: /tinyms/tinyms-api/apps/admin/user/model.py
'''
from app import app,db,auth
from flask import g

class User(db.Model):
    __tablename__ = 'sys_user'
    user_pk = db.Column(db.Integer,primary_key=True,autoincrement=True,)
    user_loginname = db.Column(db.String)
    user_password = db.Column(db.String)
    user_name = db.Column(db.String)
    user_sex = db.Column(db.String)
    user_idcard = db.Column(db.String)
    user_phone = db.Column(db.String)
    user_birthday = db.Column(db.String)
    user_email = db.Column(db.String)
    user_intime = db.Column(db.String)
    user_status = db.Column(db.String)
    fk_role_pk = db.Column(db.String)
    fk_organ_pk = db.Column(db.String)


    def __repr__(self):
        return '<User %r>' % self.user_pk

    def to_dict(items):
            lic = []
            for item in items:
                lic.append(
                    {
                        'user_pk':item.user_pk,
                        'user_loginname' : item.user_loginname,
                        'user_password' : item.user_password,
                        'user_name' : item.user_name,
                        'user_sex' : item.user_sex,
                        'user_idcard' : item.user_idcard,
                        'user_phone' : item.user_phone,
                        'user_birthday' : item.user_birthday,
                        'user_email' : item.user_email,
                        'user_intime' : item.user_intime,
                        'user_status' : item.user_status,
                        'fk_role_pk' : item.fk_role_pk,
                        'fk_organ_pk' : item.fk_organ_pk
                    }
                )
            return lic
    
    def obj_dict(item):
        lic = []
        lic.append(
                    {
                        'user_pk':item.user_pk,
                        'user_loginname' : item.user_loginname,
                        'user_password' : item.user_password,
                        'user_name' : item.user_name,
                        'user_sex' : item.user_sex,
                        'user_idcard' : item.user_idcard,
                        'user_phone' : item.user_phone,
                        'user_birthday' : item.user_birthday,
                        'user_email' : item.user_email,
                        'user_intime' : item.user_intime,
                        'user_status' : item.user_status,
                        'fk_role_pk' : item.fk_role_pk,
                        'fk_organ_pk' : item.fk_organ_pk
                    }
                )
        return lic

    